﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Classes.*;
    import Modules.realtime.*;
    import Transactions.tracking.*;

    public class TWorldState extends TFarmTransaction {

        protected static const TEMP_ID_START:int = 63000;
        protected static const TEMP_ID_END:int = 63750;

        protected static var wrappedTempIds:Boolean = false;
        protected static var m_curTempID:int = 63000;
        private static var m_tracker:DesyncTracker = new DesyncTracker();

        protected var m_save:Object;
        protected var m_object:WorldObject = null;

        public function TWorldState(_arg1:WorldObject){
            this.m_object = _arg1;
            if (((((!((this.m_object == null))) && ((this.m_object.getId() == 0)))) && (!(Global.isVisiting())))){
                this.m_object.setId(getNextTempID());
            };
            if (_arg1 != null){
                this.m_save = _arg1.getSaveObject();
            } else {
                this.m_save = null;
            };
        }
        public static function getNextTempID():int{
            var _local3:Array;
            var _local4:int;
            var _local5:WorldObject;
            var _local1:Boolean;
            var _local2:int;
            if (wrappedTempIds){
                _local3 = Global.world.getObjects();
                _local4 = 0;
                while (_local4 < _local3.length) {
                    _local5 = (_local3[_local4] as WorldObject);
                    if (_local5 != null){
                        if (_local5.getId() == m_curTempID){
                            _local1 = true;
                            break;
                        };
                    };
                    _local4++;
                };
            };
            if (_local1 == false){
                _local2 = m_curTempID;
            };
            m_curTempID++;
            if (m_curTempID > TEMP_ID_END){
                m_curTempID = TEMP_ID_START;
                wrappedTempIds = true;
            };
            return (_local2);
        }

        override public function perform():void{
            throw (new Error("Subclasses of TWorldState must override perform()"));
        }
        final override public function onAdd():void{
            super.onAdd();
            this.onWorldActionAdd();
            m_tracker.onAdd(this);
        }
        final override protected function onComplete(_arg1:Object):void{
            super.onComplete(_arg1);
            if (((((((!((this.m_object == null))) && ((((this.m_object.getId() == 0)) || ((this.m_object.getId() >= TEMP_ID_START)))))) && (_arg1.hasOwnProperty("id")))) && (!((_arg1.id == 0))))){
                this.m_object.setId(_arg1.id);
            };
            this.onWorldActionComplete(_arg1);
            m_tracker.onComplete(this);
        }
        final override protected function onFault(_arg1:int, _arg2:String):void{
            super.onFault(_arg1, _arg2);
            this.onWorldActionFault(_arg1, _arg2);
            m_tracker.onFault(this);
        }
        protected function onWorldActionAdd():void{
        }
        protected function onWorldActionComplete(_arg1:Object):void{
        }
        protected function onWorldActionFault(_arg1:int, _arg2:String):void{
        }
        protected function signedWorldAction(_arg1:String, ... _args):void{
            signedCall("WorldService.performAction", _arg1, this.m_save, _args);
            m_functionName = ("WorldService.performAction:" + _arg1);
        }
        public function getWorldObject():WorldObject{
            return (this.m_object);
        }
        public function getSaveObject():Object{
            return (this.m_save);
        }
        public function getRealtimeMethod():RealtimeMethod{
            return (null);
        }

    }
}//package Transactions 
